#include <cairo.h>  
#include <gtk/gtk.h>  
   
gchar text[7][2] = {"L","o","v","e","Y","o","u"};  
gboolean timer = TRUE;  
   
   
static gboolean  
on_expose_event(GtkWidget *widget,  
    GdkEventExpose *event,  
    gpointer data)  
{  
  cairo_t *cr;  
  cairo_text_extents_t extents;  
  static gint count = 0;  
   
  cr = gdk_cairo_create(widget->window);  
   
  cairo_select_font_face(cr,"Courier",  
      CAIRO_FONT_SLANT_NORMAL,  
      CAIRO_FONT_WEIGHT_BOLD);  
   
  cairo_set_font_size(cr, 35);   
  cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);  
   
  gint i;  
  gint x = 0;  
   
  /* 根据count数值来显示字符个数 */
  for(i = 0; i < count; i++) {  
      cairo_text_extents(cr, text[i], &extents);  
      x += extents.width + 2;  
      cairo_move_to(cr, x + 30, 50);  
      cairo_show_text(cr, text[i]);   
  }  
   
  count++;  
   
  if(count == 8) {  
      count = 0;  
  }  
   
  cairo_destroy(cr);  
   
  return FALSE;  
}  
   
static gboolean  
time_handler (GtkWidget *widget)  
{  
  if(widget->window == NULL)return FALSE;  
   
  gtk_widget_queue_draw(widget);  
  return TRUE;  
}  
   
   
int main (int argc,char*argv[])  
{  
  GtkWidget *window;  
   
  gtk_init(&argc, &argv);  
   
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  
   
  g_signal_connect(window,"expose-event",  
      G_CALLBACK(on_expose_event), NULL);  
  g_signal_connect(window,"destroy",  
      G_CALLBACK(gtk_main_quit), NULL);  
   
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);  
  gtk_window_set_default_size(GTK_WINDOW(window), 300, 90);  
  gtk_window_set_title(GTK_WINDOW(window),"LoveYou");  
  gtk_widget_set_app_paintable(window, TRUE);  
   
  
  gtk_widget_show_all(window);  
  /* 1000ms调用一次time_handler */
  g_timeout_add(1000, (GSourceFunc) time_handler, (gpointer) window);  
   
   
  gtk_main();  
   
  return 0;  
}  